package com.atguigu.spzx.manager.interceptor;

import com.atguigu.spzx.manager.properties.SpzxAuthProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * title:
 * author: zgl
 * date: 2023/12/27
 * description：
 */
@Configuration
public class SpzxWebConfigure implements WebMvcConfigurer {
    @Autowired
    private SpzxInterceptor spzxInterceptor;
    @Autowired
    private SpzxAuthProperties spzxAuthProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(spzxInterceptor).addPathPatterns("/**").excludePathPatterns(spzxAuthProperties.getAllowedPath());
                /*.excludePathPatterns(Arrays.asList("/admin/system/index/login",
                        "/admin/system/index/getCode",
                        "/doc.html",
                        "/webjars/**",
                        "/favicon.ico",
                        "/v3/api-docs/**"));*/

    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("*");
    }
}
